tools/ocaml/xb: Correct calculations of data/space the ring
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 10 Nov 2015 10:46:44 +0000 (10:46 +0000)
committerIan Campbell <ian.campbell@citrix.com>
Mon, 16 Nov 2015 11:24:47 +0000 (11:24 +0000)
commit8a2c11f876e6cf9c74f2bcaed5a997adc57da888
tree3144cc63f7dff4bb1d6228550df3ea504c9632d1
parentef6cb76026628e26e3d1ae53c50ccde1c3c78b1b
tools/ocaml/xb: Correct calculations of data/space the ring

ml_interface_{read,write}() would miscalculate the quantity of
data/space in the ring if it crossed the ring boundary, and incorrectly
return a short read/write.

This causes a protocol stall, as either side of the ring ends up waiting
for what they believe to be the other side needing to take the next
action.

Correct the calculations to cope with crossing the ring boundary.

In addition, correct the error detection.  It is a hard error if the
producer index gets more than a ring size ahead of the consumer, or if
the consumer ever overtakes the producer.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Reviewed-by: David Scott <dave@recoil.org>
tools/ocaml/libs/xb/xs_ring_stubs.c